<?php
// 获得所有医生科室信息
// header("content-type:text/html;charset=UTF-8");
include_once("conn.php");
$script = "<script src='js/adminChangeDepart.js'></script>";


$select = "SELECT * FROM doc_infos JOIN department_infos ON doc_infos.doc_TypeMain = department_infos.department_ID";

if (isset($_GET["departmentid"])) {
    $secrch_doc_department = $_GET["departmentid"];
    $select = "SELECT * FROM doc_infos JOIN department_infos ON doc_infos.doc_TypeMain = department_infos.department_ID WHERE doc_infos.doc_TypeMain = '" . $secrch_doc_department . "'";
}

$result = mysqli_query($connect_DB, $select);
if ($result) {
    echo "<div class='all-infos-div'>";
    if (mysqli_num_rows($result) > 0) {
        $count = 0;
        while ($row = mysqli_fetch_object($result)) {
            if ($count % 3 == 0) {
                echo "<div class='infos-b-div'>";
            }
            echo "
            <div class='infos-s-div'>
                <div class='s-photo-div'>
                    <img src='../public/pic/doc_imgs/".$row->doc_PhotoAddress."'>
                </div>
                <div class='s-form-div'>
                    <form id='form".$count."'>
                        <name class='docname'>".$row->doc_Name."</name>
                        <depart class='departname'>".$row->department_Name."</depart>
                        <input type='hidden' class='doctorid' name='doctorid' value='".$row->doc_ID."'>
                        <input type='hidden' class='departid' name='departid' id='d_departid' value='".$row->department_ID."'>
                        <select class='form-select select-change' name='changeDepart'>
                            <option value='none'>--选择新的科室--</option>";
                            include("a_getDepartments.php");
                        echo"</select>
                        <button class='btn btn-outline-success changebtn' type='button'>提交修改</button>
                    </form>
                </div>
            </div>";
            $count++;
            if ($count % 3 == 0) {
                echo"</div>";
            }
        }
    } else {
        $script = "";
        echo "<div class='infos-b-div'><p>暂无信息</p></div>";
    }
    echo "</div>";
} else {
    echo "<p class='s-info'>查询出错：" . $select . "</p>";
}
echo $script;
$connect_DB->close();
?>